package cn.bluemobi.platform.controller.afterSales;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bluemobi.common.core.dto.MapDto;
import cn.bluemobi.common.core.dto.PageCondition;
import cn.bluemobi.platform.core.controller.PlatformBaseController;
import cn.bluemobi.platform.core.dto.DatatablePage;
import cn.bluemobi.platform.entity.order.AfterSales;
import cn.bluemobi.platform.service.AfterSalesService;

/**
 * 
 * @author lvxh
 * 
 */
@Controller
@RequestMapping("/admin/mall/afterSales")
public class AfterSalesController extends PlatformBaseController {

    @Autowired
    private AfterSalesService afterSalesService;

    @RequestMapping("/toAfterSalesPage")
    public String toAfterSalesPage(Model model) {
        return "mall/afterSalesList";
    }

    @RequestMapping("/findAfterSaless")
    @ResponseBody
    public DatatablePage findAfterSaless(PageCondition cond) {
        return new DatatablePage(cond, afterSalesService.findAfterSaless(cond));
    }

    @RequestMapping("/toAfterSalesDetailPage")
    public String toAfterSalesDetailPage(@RequestParam(value = "afterSalesId", required = false) String afterSalesId,
            ModelMap model) {
        if (!StringUtils.isEmpty(afterSalesId)) {
            AfterSales afterSales = afterSalesService.findAfterSalesDetail(afterSalesId);
            model.put("afterSales", afterSales);
        }
        return "mall/afterSalesDetail";
    }

    @RequestMapping("/deleteAfterSales")
    @ResponseBody
    public MapDto deleteById(@RequestParam("afterSalesId") String afterSalesId) {
        return afterSalesService.deleteAfterSales(afterSalesId, getUser());
    }

    @RequestMapping("/auditing")
    @ResponseBody
    public MapDto auditing(@RequestParam("afterSalesId") String afterSalesId, @RequestParam("orderId") String orderId) {
        return afterSalesService.auditing(afterSalesId, orderId, getUser());
    }

    @RequestMapping("/confirmPayment")
    @ResponseBody
    public MapDto confirmPayment(@RequestParam("afterSalesId") String afterSalesId) {
        return afterSalesService.confirmPayment(afterSalesId, getUser());
    }

    @RequestMapping("/refuseAuditing")
    @ResponseBody
    public MapDto refuseAuditing(@RequestParam("afterSalesId") String afterSalesId,
            @RequestParam("refuseReason") String refuseReason) {
        return afterSalesService.refuseAuditing(afterSalesId, refuseReason, getUser());
    }
}
